#include<iostream>
#include<pthread.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<unistd.h>
const int num=10;
void *thread_func(void *arg){
    std::string *str((std::string*)arg);
    int cnt=5;
    while(cnt--){
        std::cout<<" new thread "<<*str<<std::endl;
        sleep(1);
    }
    delete str;
    return nullptr;
}
int main(){
    std::vector<pthread_t> tids;
    for(int i=0;i<num;i++){
        pthread_t tid;
        std::string *str=new std::string("thread"+std::to_string(i));
        int n=pthread_create(&tid,NULL,thread_func,str);
        if(n==0)
          tids.push_back(tid);
          else{
            continue;
          }
    }
    for(auto& t:tids){    
        pthread_join(t,NULL);
    }
    return 0;
}